package com.hmkj.core.model.amount;

import com.hmkj.core.exception.BussinessException;
import com.hmkj.core.po.amount.Cash;
import com.hmkj.core.po.amount.Recharge;
import com.hmkj.core.po.user.User;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Donfy on 2017/6/18.
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class CashModel extends Cash {

    private Integer userBankId;
    /**
     * 支付密码
     */
    private String payPassword;

    /**
     * 用户相关信息
     */
    private User u;

    /**
     * 审核状态 1通过，2不通过
     */
    private Integer auditStatus;


    public void checkCash() {
        if (getAmount() == null) throw new BussinessException("提现金额不能为空");
        if (getAmount().compareTo(BigDecimal.ZERO) != 1) throw new BussinessException("提现金额必须大于0");
    }

    /**1,1通过:T1<br>2,不通过:T2**/

    public enum AUDITSTATUS {

        /**1,1通过:T1**/
        T1("1通过",1),

        /**2,不通过:T2**/
        T2("不通过",2);

        public final int code;
        public final String value;
        private static Map<Integer, String> map = new HashMap<Integer, String>();

        AUDITSTATUS(String value, int code) {
            this.code = code;
            this.value = value;
        }

        public static String getValue(Integer code) {
            if (null == code) {
                return null;
            }
            for (CashModel.AUDITSTATUS auditStatus : CashModel.AUDITSTATUS.values()) {
                if (auditStatus.code == code) {
                    return auditStatus.value;
                }
            }
            return null;
        }

        public static Integer getCode(String value) {
            if (null == value  || "".equals(value)) {
                return null;
            }
            for (CashModel.AUDITSTATUS auditStatus : CashModel.AUDITSTATUS.values()) {
                if (auditStatus.value.equals(value)) {
                    return auditStatus.code;
                }
            }
            return null;
        }

        public static  Map<Integer, String> getEnumMap() {
            if(map.size() == 0){
                for (CashModel.AUDITSTATUS auditStatus : CashModel.AUDITSTATUS.values()) {
                    map.put(auditStatus.code,auditStatus.value);
                }
            }
            return map;
        }
    }


//
//    /**
//     * 格式化提现记录
//     *
//     * @param userId        操作用户id
//     * @param userBank      用户银行卡信息id
//     * @param amount        操作金额
//     * @param actualArrival 实际到账金额（手续费自承情况）
//     * @param fee           手续费
//     * @param status        状态
//     * @return
//     */
//    public static Cash formatEntity(Integer userId, UserBank userBank, BigDecimal amount, BigDecimal actualArrival, BigDecimal fee, STATUS status) {
//        Cash c = new Cash();
//        c.setUserId(userId);
//        c.setBankName(userBank.getBankName());
//        c.setBankNo(userBank.getBankNo());
//        c.setBranch(userBank.getBranch());
//        c.setAmount(amount);
//        c.setActualArrival(actualArrival);
//        c.setFee(fee);
//        c.setStatus(status.code);
//        c.setOrderNo(OrderNoUtils.getSerialNumber());
//        return c;
//    }
}
